package people

import(
	"fmt"
	"math"
)
//人物
type person struct{
	name	string				//名称
	age		int					//年龄
}

//力量
type power struct{
	attack		int				//攻击力
	defense		int				//护甲值
}
//位置坐标
type location struct{
	x		float64				
	y		float64
	z		float64
}
//非玩家角色
type nonPlayerCharacter struct{
	name		string					//名称
	speed		int						//速度
	hp			int						//血量
	power		power					//力量
	loc			location				//坐标
}
//攻击属性
type attacker struct{
	attackpower int
	dmgbonus	int
}
//武器->剑
type sword struct{
	attacker
	twohanded	bool
}
//武器->枪
type gun struct{
	attacker
	bulletsremaining	int
}
//挥舞一把椅子
type chair struct{
	legcount	int
	leather		bool
}
//武器接口
type weapon interface{
	Wield() bool
}
//剑
func (s sword) Wield() bool {
	fmt.Println("你挥舞着一把剑！")
	return true
}
//枪
func (g gun) Wield() bool{
	fmt.Println("您挥舞着一杆枪！")
	return true
}
//椅子
func (c chair) Wield() bool{
	fmt.Println("您在挥舞一把椅子")
	return true
}

//建立非玩家角色
func AddNonPlayerCharacter() { 
	demo_1 := nonPlayerCharacter{
		name:"史莱姆",
		speed:10,
		hp:100,
		power:power{attack:15,defense:10},
		loc:location{x:100.1,y:120.25,z:10.35},
	}
	demo_2 := nonPlayerCharacter{
		name:"史莱姆护卫",
		speed:15,
		hp:2500,
		power:power{attack:25,defense:40},
		loc:location{x:100.80,y:122.10,z:30.45},
	}
	fmt.Printf("%v与%v相距%f米\n",demo_1.name, demo_2.name, demo_1.distanceTo(demo_2))
}
//武器
func SwordWield(){
	sword_1 := sword{
		attacker:attacker{attackpower:1, dmgbonus:5},
		twohanded:true,
	}
	gun_1 := gun{
		attacker:attacker{attackpower:10,dmgbonus:20},
		bulletsremaining:11,
	}
	fmt.Printf("武器： 剑： %v, 枪：%v\n",sword_1,gun_1)
	sword_1.Wield()
	gun_1.Wield()

	wielder(sword_1)
	wielder(gun_1)	

	chair_1 := chair{legcount: 3, leather: true}
	wielder(chair_1)
}

//舞动武器
func wielder (w weapon) bool {
	fmt.Println("Wielding......")
	return w.Wield()
}

//计算距离
func (loc location) euclideanDistance(targer location) float64{
	return math.Sqrt((loc.x - targer.x)*(loc.x-targer.x) + (loc.y - targer.y)*(loc.y - targer.y) + (loc.z - targer.z)*(loc.z - targer.z))
}
func (npc nonPlayerCharacter) distanceTo(target nonPlayerCharacter) float64{
	return npc.loc.euclideanDistance(target.loc)
}